package com.jackstraw.commoncode.pojo;

import lombok.Data;

/**
 * 所在包：com.jackstraw.commoncode.pojo
 * 文件名：
 * 版权：jackstraw.
 * 项目：common-code
 * 功能描述：
 * 修改人：稻草人
 * 修改时间：2022-04-02 16:29
 */
@Data
public class Result {

    /**
     * 默认失败消息
     */
    private static final String DEFAULT_FAILURE_MSG = "操作失败！";
    /**
     * 默认成功消息
     */
    private static final String DEFAULT_SUCCESS_MSG = "操作成功！";
    /**
     * 默认失败编码
     */
    private static final Integer DEFAULT_FAILURE_CODE = 500;
    /**
     * 默认成功编码
     */
    private static final Integer DEFAULT_SUCCESS_CODE = 200;

    public Result() {

    }

    public Result(String message, Integer code, Boolean result) {
        this.message = message;
        this.code = code;
        this.result = result;
    }

    public Result(String message, Integer code, Boolean result, Object data) {
        this.message = message;
        this.code = code;
        this.result = result;
        this.data = data;
    }

    /**
     * 回执消息
     */
    private String message;

    /**
     * 返回编码
     */
    private Integer code;

    /**
     * 返回结果
     */
    private Boolean result;

    /**
     * 返回数据
     */
    private Object data;

    public static Result success() {
        return new Result(DEFAULT_SUCCESS_MSG, DEFAULT_SUCCESS_CODE, true);
    }

    public static Result success(String message) {
        return new Result(message, DEFAULT_SUCCESS_CODE, true);
    }

    public static Result success(String message, Integer code) {
        return new Result(message, code, true);
    }

    public static Result success(Integer code) {
        return new Result(DEFAULT_SUCCESS_MSG, code, true);
    }

    public static Result error() {
        return new Result(DEFAULT_FAILURE_MSG, DEFAULT_FAILURE_CODE, true);
    }

    public static Result error(String message) {
        return new Result(message, DEFAULT_FAILURE_CODE, true);
    }

    public static Result error(String message, Integer code) {
        return new Result(message, code, true);
    }

    public static Result error(Integer code) {
        return new Result(DEFAULT_FAILURE_MSG, code, true);
    }
}
